﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
using System.Configuration;
using System.Xml;
using System.Xml.Linq;
using System.Windows.Forms;

namespace XMLMovieWebsite
{
    public partial class FilmDetail : System.Web.UI.Page
    {
        String getKey_phim;
        protected void Page_Load(object sender, EventArgs e)
        {
            getKey_phim = Request.QueryString["id"];
            loadDulieuRaFileXML();
            layDulieuTuXML();
        }
        
        public void loadDulieuRaFileXML()
        {
            try
            {
                string ConString = ConfigurationManager.ConnectionStrings["ConStringXml"].ConnectionString;
                //string CMDString = "SELECT id,name,time, rating" + "FROM allMovie FOR XML RAW ('Movie'), ROOT('root'), ELEMENTS";
                string CMDString = " SELECT  * FROM movie_thao where  id = '"+getKey_phim+"'";
                SqlConnection con;
                SqlCommand cmd;
                SqlDataAdapter sda;
                DataTable dt;


                using (con = new SqlConnection(ConString))
                {
                    cmd = new SqlCommand(CMDString, con);
                    con.Open();
                    dt = new DataTable("Movie");
                    sda = new SqlDataAdapter(cmd);
                    sda.Fill(dt);
                    if (dt != null)
                    {

                        dt.WriteXml(Server.MapPath("~/App_Data/ChiTiet.xml"));
                    }
                    con.Close();

                }
            }
            catch (Exception)
            {

            }


        }
        public void layDulieuTuXML()
        {
            using (DataSet ds = new DataSet())
            {
                ds.ReadXml(Server.MapPath("~/App_Data/ChiTiet.xml"));
                
                DataTable dt = new DataTable();
                dt = ds.Tables["Movie"];


                id_details.DataSource = dt;
                id_details.DataBind();
               

            }
        }
    }           
        
}